<?php
	include_once 'Usuario.php';
	include_once 'Paper.php';

	class Revisor extends Usuario
	{
		public $Resena;
		public $Tracks;
		public $Idiomas;
		//Almacena el estado de la calificacion de un revisor en particular
		public $EstadoDeRevisor;
		
		public function Insertar(){
			global $dbh;
			parent::Insertar();
		
			$sql = "select count(*) from revisor where idusuario = '".$this->IdUsuario."'";
			
			if ($res = $dbh->query($sql)) {			
				if ($res->fetchColumn() > 0) {
					$sql = "update revisor set resena = '".$this->Resena."', tracks = '".$this->Tracks."', idiomas = '".$this->Idiomas."'
							where idusuario = ".$this->IdUsuario.";
					";
					
					$temp_q_id = $dbh->prepare($sql);
					$temp_q_id->execute();					
				}else{
					$sql = "insert into revisor (idusuario, resena, tracks, idiomas) values ('".$this->IdUsuario."','".$this->Resena."','".$this->Tracks."','".$this->Idiomas."')";
					$temp_q_id = $dbh->prepare($sql);
					$temp_q_id->execute();					
				}
			}
		}
		
		static public function Obtener($idusuario){
			global $dbh;
			$sql = "select resena,tracks,idiomas from revisor where idusuario = '".$idusuario."'";
			
			$obj = new Revisor();
			foreach($dbh->query($sql) as $row){
				$obj->Resena = $row['resena'];
				$obj->Tracks = $row['tracks'];
				$obj->Idiomas = $row['idiomas'];
			}
			
			return $obj;
		}
		
		static public function DatosAdicionales($idusuario, $tracks, $idiomas){
			global $dbh;
			$sql = "select count(*) from revisor where idusuario = '".$idusuario."'";
			//echo $sql;
			if ($res = $dbh->query($sql)) {							
				if ($res->fetchColumn() > 0) {
					//resena = '".$resena."',
					$sql = "update revisor set  tracks = '".$tracks."', idiomas = '".$idiomas."'
							where idusuario = ".$idusuario.";
					";
					echo $sql;
					$temp_q_id = $dbh->prepare($sql);
					$temp_q_id->execute();					
				}else{
					$sql = "insert into revisor (idusuario, tracks, idiomas) values (
						'".$idusuario."',
						'".$tracks."',
						'".$idiomas."')";
						echo $sql;
					$temp_q_id = $dbh->prepare($sql);
					$temp_q_id->execute();					
				}
			}		
		}
	}
?>